<script setup lang="ts">
import { getAd2 } from '@/api/getAxios';
import { ref } from 'vue'

const data = ref()

getAd2().then((res) => {
    data.value = showData(res.data.result.gameList, 1) 
})
const showData = function (arr: any, count: number) {
    var shuffled = arr.slice(0),
        i = arr.length,
        min = i - count,
        temp, index;
    while (i-- > min) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    }
    return shuffled.slice(min);
}
</script>
<template>
    <p class="like">猜你喜欢</p>
    <div class="main" v-if="data">
        <div class="pic">
            <p>
                <img :src="data[0].game_icon" alt="">
            </p>
            <div>
                <p>{{ data[0].game_name }}</p>
                <p>{{ data[0].game_type_name }}</p>
            </div>
        </div>
        <button><a :href="data[0].jump_url" target="_blank">进入游戏</a></button>
    </div>
</template>

<style scoped lang='less'>
.main {
    padding: 10px;
    margin: 0 10px;
    display: flex;
    align-items: center;
    margin-top: 10px;
    justify-content: space-between;
    background-color: white;
    border-radius: 8px;

    .pic>p:nth-child(1) {
        width: 20%;

        img {
            width: 100%;
            border-radius: 8px;
        }
    }

    >div {
        display: flex;

        p:nth-child(2) {
            color: #888;
            font-size: .9rem;
        }

        >div {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            margin-left: 10px;
        }
    }

    button {
        border: 0;
        width: 220px;
        padding: 6px 0;
        border-radius: 8px;
        font-size: .85rem;
        background-color: var(--mcolor);
        color: whitesmoke;
        transition: all 0.2s;
        a{
            color: whitesmoke;
        }
        &:active {
            opacity: 0.8;
        }
    }
}

.like {
    margin-top: 100px;
    text-align: center;
    color: #888;
}
</style>